package it.polimi.comorazio.activities;

import it.polimi.comorazio.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class Menu extends ListActivity {

	private enum MenuFields {
		name, description
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setTitle(getString(R.string.label_menu_app));

		getListView().setBackgroundColor(Color.rgb(235, 235, 235));

		ArrayList<Map<String, String>> list = buildData();

		String[] from = { MenuFields.name.toString(),
				MenuFields.description.toString() };

		int[] to = { android.R.id.text1, android.R.id.text2 };

		SimpleAdapter adapter = new SimpleAdapter(this, list,
				android.R.layout.simple_list_item_2, from, to) {
			@Override
			public View getView(int position, View convertView, ViewGroup parent) {
				View v = super.getView(position, convertView, parent);
				TextView t = (TextView) ((ViewGroup) v).getChildAt(1);
				t.setTextColor(Color.rgb(111, 111, 111));
				return v;
			}
		};

		setListAdapter(adapter);
	}

	private ArrayList<Map<String, String>> buildData() {
		ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
		list.add(putData(getString(R.string.menu_option_tour),
				getString(R.string.menu_option_tour_desc)));
		list.add(putData(getString(R.string.menu_option_poi),
				getString(R.string.menu_option_poi_desc)));
		list.add(putData(getString(R.string.menu_option_arch),
				getString(R.string.menu_option_arch_desc)));
		return list;
	}

	private HashMap<String, String> putData(String name, String description) {
		HashMap<String, String> item = new HashMap<String, String>();
		item.put(MenuFields.name.toString(), name);
		item.put(MenuFields.description.toString(), description);
		return item;
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		if (position == 0) {
			Intent intent = new Intent(getApplicationContext(), Tour.class);
			startActivity(intent);
		} else if (position == 1) {
			Intent intent = new Intent(getApplicationContext(),
					PointOfInterestListActivity.class);
			startActivity(intent);
		} else if (position == 2) {
			Intent intent = new Intent(getApplicationContext(),
					ArchitectListActivity.class);
			startActivity(intent);
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

}
